package user

import (
	"context"

	"mydemo/api/rewark/internal/svc"
	"mydemo/api/rewark/internal/types"
	"mydemo/rpc/user/types/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type AllUserLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAllUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AllUserLogic {
	return &AllUserLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AllUserLogic) AllUser() (resp *types.AllUserOutput, err error) {
	// todo: add your logic here and delete this line
	out := &types.AllUserOutput{}
	res, err := l.svcCtx.UserRpc.GetUserList(l.ctx, &user.GetUserListInput{})
	if err != nil {
		return out, err
	}
	out.Total = int(res.Total)
	for _, v := range res.List {
		out.Data = append(out.Data, &types.AllUser{
			Id:       uint(v.Id),
			Name:     v.Name,
			PassWord: v.PassWord,
			Gender:   v.Gender,
		})
	}
	return out, nil
}
